package com.zjitc;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.GsonHttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import java.util.List;

/**
 * Created by lenovo on 2018/4/1.
 */
@Configuration
@ComponentScan(basePackageClasses = MyWebMvcConfiguration.class)
public class MyWebMvcConfiguration extends WebMvcConfigurationSupport {

    /**
     * 	protected final List<HttpMessageConverter<?>> getMessageConverters() {
     if (this.messageConverters == null) {
     this.messageConverters = new ArrayList<HttpMessageConverter<?>>();
     configureMessageConverters(this.messageConverters);
     if (this.messageConverters.isEmpty()) {
     addDefaultHttpMessageConverters(this.messageConverters);
     }
     extendMessageConverters(this.messageConverters);
     }
     return this.messageConverters;
     }
     * @param converters
     */
    @Override
    protected void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
        for (HttpMessageConverter converter : converters) {
            if (converter instanceof GsonHttpMessageConverter) {
                GsonHttpMessageConverter gsonHttpMessageConverter = (GsonHttpMessageConverter) converter;
                gsonHttpMessageConverter.setGson(GsonOfDate.getInstance());
            }
        }
    }
}
